<?php

namespace App\HttpController\Api;

use App\Core\Output;
use App\Logic\Member\MemberService;
use EasySwoole\Http\Message\Status;

/**
 * Class Member
 * 会员
 */
class Member extends BaseController {
    /**
     * 注册用户
     */
    public function register()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->createUser($data);
        return $this->writeJsonByOutput($result);
    }
    /**
     * 登录
     */
    public function login()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->login($data['username'], $data['password']);
        return $this->writeJsonByOutput($result);
    }

    /**登出*/
    public function logout()
    {
        $data = [];
        $result = (new Output())->setStatusCode(Status::CODE_OK)->setMsg('success')->setData($data);
        return $this->writeJsonByOutput($result);
    }

    /**
     * 用户信息
     * @return bool
     */
    public function info()
    {
        $service = new MemberService();
        $result = $service->info($this->request());
        return $this->writeJsonByOutput($result);
    }

    /**重置密码
     */
    public function resetPassword()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->resetPassword($data);
        return $this->writeJsonByOutput($result);
    }

    /**修改USDT
     */
    public function editUsdt()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->editUsdt($data);
        return $this->writeJsonByOutput($result);
    }

    /**修改币安地址
     */
    public function editBinance()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->editBinance($data);
        return $this->writeJsonByOutput($result);
    }

    /**修改波场地址
     */
    public function editTrx()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->editTrx($data);
        return $this->writeJsonByOutput($result);
    }

    /**修改对公账户
     */
    public function editPubBank()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->editPubBank($data);
        return $this->writeJsonByOutput($result);
    }

    /**修改对私账户
     */
    public function editPriBank()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->editPriBank($data);
        return $this->writeJsonByOutput($result);
    }
    /**我推荐的用户*/
    public function referrer()
    {
        $service = new MemberService();
        $result = $service->referrer($this->request());
        return $this->writeJsonByOutput($result);
    }

    /**设置每单提成*/
    public function setProfit()
    {
        $service = new MemberService();
        $data = $this->getJson();
        $result = $service->setProfit($data);
        return $this->writeJsonByOutput($result);
    }
    /**获取每单提成*/
    public function getProfit()
    {
        $service = new MemberService();
        $result = $service->getProfit();
        return $this->writeJsonByOutput($result);
    }
    /**获取推荐关系链提成*/
    public function getProfitChain()
    {
        $service = new MemberService();
        $id = $this->request()->getQueryParams()['id'];
        $result = $service->findAllRecommendedChainProfit($id);
        $firstProfit = reset($result);
        $lastProfit = end($result);
        return $this->writeJson(200, $result);
    }

}
